<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="cn.egame.interfaces.gc.GameInfo"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.9.1.js"></script>
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/css/main.css"  />
<script type="text/javascript">
	function searchGame(){
		myform = document.getElementById("myForm");
		myform.submit();
	};
	function changeLabel(labelstr){
		var labelList = labelstr.split(",");	
		var labelInputs = document.getElementsByName("gamelabel");
		for(var j=0;j<5;j++){
			labelInputs[j].value = "";
		}
		for(var i=0;i<labelList.length && i<5;i++){
			labelInputs[i].value = labelList[i];
		}
	}
	function saveLabel(){
		var labels = document.getElementsByName("gamelabel");
		var labelStr = "";
		for(var i=0;i<labels.length;i++){			
			if(labels[i].value != ""){
				labelStr = labelStr + "," + labels[i].value;
			}
		}
		
		labelStr = labelStr.substring(1,labelStr.length);
		//重新对游戏列表赋值
		
		$.ajax({			
			url : "<%=request.getContextPath() + "/caidan/game/update/label.do" %>",
			type : 'post',
			data : {
				'gid' : $('#gameId').val(),
				'label' : labelStr
			},
			success : function(msg) {	
				alert("保存成功！");
				var index = document.getElementById("gameId").selectedIndex;
				var gId = $('#gameId').val();
				document.getElementById("gameId").options[index].setAttribute("onclick","changeLabel('"+ labelStr +"')");	
			}
		});
	}
	
	function doImport() {
		var gametag = document.getElementById("game_file").value;
		if(gametag.substring(gametag.lastIndexOf(".")+1) != "xls" && gametag.substring(gametag.lastIndexOf(".")+1) != "xlsx") {
			alert("只能上传Excel文件");
			return false;
		}
		document.getElementById("myForm").action="<%=request.getContextPath() + "/caidan/game/update/label/import.do" %>";
		document.getElementById("myForm").submit();
	}
	
	function doExport() {
		document.getElementById("myForm").action="<%=request.getContextPath() + "/caidan/game/update/label/export.do" %>";
		document.getElementById("myForm").submit();
	}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>游戏标签</title>
</head>
<body>
	<form id="myForm" action="<%=request.getContextPath() + "/caidan/game/label.do"%> "  method="post" enctype="multipart/form-data">
	<div class="matter_box">
		<h3 class="nopoint"><strong>游戏标签</strong></h3>
		<div class="task_search">
			<p>
				<span>游戏名称：</span><input type=text name="gname"><input type=button value="查询" class="btn3" onclick="javascript:searchGame()">
				<span>导入游戏标签：</span> <input type="file" name="filePath" id="game_file">
				<a href="javascript:void(0)" onclick="doImport()" id="importBtn" class="btn3">导&nbsp;入</a>
				<a href="javascript:void(0)" onclick="doExport()" id="exportBtn" class="btn3">导&nbsp;出</a>
			</p>
			
		
		<div class="mt10 pt10 clearfix">
		<table class="table2">
			<tr>
				<th>游戏列表</th>
				<th>游戏标签 </th>
			</tr>
			<tr>
				<td>
					<select size="10" id="gameId" style="width: 171px;">					
						<% 
							if(request.getAttribute("gameList")!=null){
								List<GameInfo> list = (List<GameInfo>)request.getAttribute("gameList");
								for(GameInfo bean:list){
									%>
										<option value=<%=bean.getGId() %> onclick="changeLabel('<%=bean.getGameLabel() %>')">【<%=bean.getGId() %>】<%=bean.getGameName() %></option>
									<%
								}
							}
						%>
					</select>
				</td>
				<td class="input_td">
					<input type=text name=gamelabel value=""><br/>
					<input type=text name=gamelabel value=""><br/>
					<input type=text name=gamelabel value=""><br/>
					<input type=text name=gamelabel value=""><br/>
					<input type=text name=gamelabel value=""><br/>
					<input type=button onclick="saveLabel()" value="保存" class="btn3">
				</td>
			</tr>			
		</table>
		</div>
		</div>
	</div>
	</form>
</body>
</html>